/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Frame;

import java.awt.Image;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.text.html.parser.Parser;
import ufc.quixada.es.controlador.ControladorBanco;
import ufc.quixada.es.controlador.ControladorJogador;
import ufc.quixada.es.model.Jogador;

/**
 *
 * @author wagner
 */
public class TesteTeste extends javax.swing.JFrame {
    /**
     * Creates new form TesteTeste
     */
    ControladorBanco controladorBanco;
    ControladorJogador controladorJogador;
    Jogador jogador;

    public TesteTeste(ControladorJogador controladorJogador) throws Exception {
        initComponents();
        controladorBanco = new ControladorBanco();
        this.controladorJogador= controladorJogador;
        pitarAvatar();
        jogadorDaVez();
    //    mostraInformacoesJogador(jogador);
    
    }

    

    public void pitarAvatar() throws Exception{
         jLabelImagemJogador1.setLocation(850, 620);
         jLabelImagemJogador1.setIcon(new ImageIcon(controladorJogador.jogadorDaVez().getIdAvatar()));
        
         //adicionar Avatar aqui.
         jLabelImagemJogador2.setLocation(850,620);
         jLabelImagemJogador2.setIcon(new ImageIcon(controladorJogador.jogadorDaVez().getIdAvatar()));
      
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelImagemJogador1 = new javax.swing.JLabel();
        jLabelImagemJogador2 = new javax.swing.JLabel();
        jTextFieldInserirNome = new javax.swing.JTextField();
        jTextFieldInserirSaldo = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabelNome = new javax.swing.JLabel();
        jLabelSaldo = new javax.swing.JLabel();
        RealizarJogada = new javax.swing.JButton();
        jTextFieldGetDado1 = new javax.swing.JTextField();
        jTextFieldGetDado2 = new javax.swing.JTextField();
        jButtonPassarAVez = new javax.swing.JButton();
        Fundo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabelImagemJogador1.setText("f");
        getContentPane().add(jLabelImagemJogador1, new org.netbeans.lib.awtextra.AbsoluteConstraints(840, 640, 90, 100));
        getContentPane().add(jLabelImagemJogador2, new org.netbeans.lib.awtextra.AbsoluteConstraints(840, 640, 110, 100));

        jTextFieldInserirNome.setEditable(false);
        jTextFieldInserirNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldInserirNomeActionPerformed(evt);
            }
        });
        getContentPane().add(jTextFieldInserirNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(1060, 300, 180, -1));

        jTextFieldInserirSaldo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldInserirSaldoActionPerformed(evt);
            }
        });
        getContentPane().add(jTextFieldInserirSaldo, new org.netbeans.lib.awtextra.AbsoluteConstraints(1060, 340, 180, -1));

        jButton1.setText("Sair");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1179, 440, 80, -1));

        jLabelNome.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        jLabelNome.setForeground(new java.awt.Color(254, 254, 254));
        jLabelNome.setText("Nome:");
        getContentPane().add(jLabelNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(980, 300, -1, -1));

        jLabelSaldo.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        jLabelSaldo.setForeground(new java.awt.Color(254, 254, 254));
        jLabelSaldo.setText("Saldo:");
        getContentPane().add(jLabelSaldo, new org.netbeans.lib.awtextra.AbsoluteConstraints(980, 340, -1, -1));

        RealizarJogada.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/realizarJogadaPequeno3.png"))); // NOI18N
        RealizarJogada.setBorderPainted(false);
        RealizarJogada.setContentAreaFilled(false);
        RealizarJogada.setDefaultCapable(false);
        RealizarJogada.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/realizarJogadarGrande3.png"))); // NOI18N
        RealizarJogada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RealizarJogadaActionPerformed(evt);
            }
        });
        getContentPane().add(RealizarJogada, new org.netbeans.lib.awtextra.AbsoluteConstraints(990, 110, 290, -1));

        jTextFieldGetDado1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldGetDado1ActionPerformed(evt);
            }
        });
        getContentPane().add(jTextFieldGetDado1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1080, 40, 100, -1));

        jTextFieldGetDado2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldGetDado2ActionPerformed(evt);
            }
        });
        getContentPane().add(jTextFieldGetDado2, new org.netbeans.lib.awtextra.AbsoluteConstraints(1080, 80, 100, -1));

        jButtonPassarAVez.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/PassaePequeno.png"))); // NOI18N
        jButtonPassarAVez.setBorderPainted(false);
        jButtonPassarAVez.setContentAreaFilled(false);
        jButtonPassarAVez.setDefaultCapable(false);
        jButtonPassarAVez.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/PassarAVezGrande.png"))); // NOI18N
        jButtonPassarAVez.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPassarAVezActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonPassarAVez, new org.netbeans.lib.awtextra.AbsoluteConstraints(1000, 170, 280, 60));

        Fundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Tabuleiro2.png"))); // NOI18N
        getContentPane().add(Fundo, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, -220, 1580, 1170));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void RealizarJogadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RealizarJogadaActionPerformed
         movimentaNaTela();
        movimentaOJogador();
    
    }//GEN-LAST:event_RealizarJogadaActionPerformed
   
    
    public void movimentaNaTela(){
        
        int dado1= Integer.parseInt(jTextFieldGetDado1.getText());
        int dado2= Integer.parseInt(jTextFieldGetDado2.getText());
        if(jogador.getId()==1){
            movimentarPersonagem(dado1+dado2, jLabelImagemJogador1);
        }else if(jogador.getId()==2){     
            movimentarPersonagem(dado1+dado2, jLabelImagemJogador2);
        }

        RealizarJogada.setEnabled(false);   
        
    } 
    public void movimentaOJogador(){
        int dado1= Integer.parseInt(jTextFieldGetDado1.getText());
        int dado2= Integer.parseInt(jTextFieldGetDado2.getText());
    
        controladorBanco.jogada(jogador,dado1+dado2);
        setNovoSaldo();
        
    }
 public void setNovoSaldo(){   
        String novoSaldo = Integer.toString(jogador.getSaldo());
        jTextFieldInserirSaldo.setText(novoSaldo);
    
 }
    public void jogadorDaVez() throws Exception{
    jogador = controladorJogador.jogadorDaVez();
    String saldo = Integer.toString(jogador.getSaldo());
   jTextFieldInserirNome.setText(jogador.getNome());
   jTextFieldInserirSaldo.setText(saldo);
    } 
    
    
    public void movimentarPersonagem(int numero, JLabel j){
       
        int x=80;
        int y=620;
        for(int i=0; i<numero; i++){
        j.setLocation(j.getX()-x,y);   
        }
    }
    
    private void jTextFieldGetDado2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldGetDado2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldGetDado2ActionPerformed

    private void jTextFieldGetDado1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldGetDado1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldGetDado1ActionPerformed

    private void jButtonPassarAVezActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPassarAVezActionPerformed
           
            RealizarJogada.setEnabled(true);
            jTextFieldGetDado1.setText(null);
            jTextFieldGetDado2.setText(null);
      
        try {
                jogadorDaVez();
        } catch (Exception ex) {
            Logger.getLogger(TesteTeste.class.getName()).log(Level.SEVERE, null, ex);
        }
  

    }//GEN-LAST:event_jButtonPassarAVezActionPerformed

    private void jTextFieldInserirNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldInserirNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldInserirNomeActionPerformed

    private void jTextFieldInserirSaldoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldInserirSaldoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldInserirSaldoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
      
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Fundo;
    private javax.swing.JButton RealizarJogada;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonPassarAVez;
    private javax.swing.JLabel jLabelImagemJogador1;
    private javax.swing.JLabel jLabelImagemJogador2;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelSaldo;
    private javax.swing.JTextField jTextFieldGetDado1;
    private javax.swing.JTextField jTextFieldGetDado2;
    private javax.swing.JTextField jTextFieldInserirNome;
    private javax.swing.JTextField jTextFieldInserirSaldo;
    // End of variables declaration//GEN-END:variables
}
